package com.lxmes.business.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.lxmes.business.domain.CcChukuMain;
import com.lxmes.common.utils.SecurityUtils;
import io.swagger.annotations.*;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.lxmes.common.annotation.Log;
import com.lxmes.common.core.controller.BaseController;
import com.lxmes.common.core.domain.AjaxResult;
import com.lxmes.common.enums.BusinessType;
import com.lxmes.business.domain.CcStockinfoInfo;
import com.lxmes.business.service.ICcStockinfoInfoService;
import com.lxmes.common.utils.poi.ExcelUtil;
import com.lxmes.common.core.page.TableDataInfo;

/**
 * 库存信息Controller
 * 
 * @author 王超
 * @date 2022-06-12
 */
@Api(tags="库存信息")
@RestController
@RequestMapping("/business/stockinfo")
public class CcStockinfoInfoController extends BaseController
{
    @Autowired
    private ICcStockinfoInfoService ccStockinfoInfoService;

    /**
     * 查询库存信息列表
     */
    @PreAuthorize("@ss.hasPermi('business:stockinfo:list')")
    @GetMapping("/list")
    public TableDataInfo list(CcStockinfoInfo ccStockinfoInfo)
    {
        ccStockinfoInfo.setDeptId(SecurityUtils.getDeptId());
        startPage();
     /*   if("库存不足".equals(ccStockinfoInfo.getYjflag())){
            ccStockinfoInfo.setYjflag1("库存不足");
            ccStockinfoInfo.setYjflag(null);
        }
        List<CcStockinfoInfo> list = ccStockinfoInfoService.selectCcStockinfoInfoListJc(ccStockinfoInfo);*/
        List<CcStockinfoInfo> list = ccStockinfoInfoService.selectCcStockinfoInfoListSum(ccStockinfoInfo);
        return getDataTable(list);
    }

    @PreAuthorize("@ss.hasPermi('business:stockinfo:list')")
    @GetMapping("/listinfo")
    public TableDataInfo listinfo(CcStockinfoInfo ccStockinfoInfo)
    {
        ccStockinfoInfo.setDeptId(SecurityUtils.getDeptId());
        startPage();
        List<CcStockinfoInfo> list = ccStockinfoInfoService.selectListinfo(ccStockinfoInfo);
        return getDataTable(list);
    }

    @GetMapping("/selectList")
    public TableDataInfo selectList(CcStockinfoInfo ccStockinfoInfo)
    {
        ccStockinfoInfo.setDeptId(SecurityUtils.getDeptId());
        startPage();
        if("库存不足".equals(ccStockinfoInfo.getYjflag())){
            ccStockinfoInfo.setYjflag1("库存不足");
            ccStockinfoInfo.setYjflag(null);
        }
        List<CcStockinfoInfo> list = ccStockinfoInfoService.selectCcStockinfoInfoSelectList(ccStockinfoInfo);
        return getDataTable(list);
    }


    /**
     * 查询库存信息列表
     */
    @ApiOperation(value="库存列表")
    //查询条件
    @ApiImplicitParams({
            @ApiImplicitParam(name = "queryParams", value = "物料号、物料名称、仓库编号", paramType="query", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "pageSize", value = "分页大小",  required = true,paramType="query",  dataType = "int", dataTypeClass = Integer.class),
            @ApiImplicitParam(name = "pageNum", value = "当前页数",  required = true,paramType="query",   dataType = "int", dataTypeClass = Integer.class)
    })
    @ApiResponses({@ApiResponse(code=200,message = "0k",response = CcChukuMain.class)})
    @PreAuthorize("@ss.hasPermi('mobile:stockinfo:list')")
    @GetMapping("/mobileKcList")
    public TableDataInfo mobileKcList(CcStockinfoInfo ccStockinfoInfo)
    {
        ccStockinfoInfo.setDeptId(SecurityUtils.getDeptId());
        startPage();
        if("库存不足".equals(ccStockinfoInfo.getYjflag())){
            ccStockinfoInfo.setYjflag1("库存不足");
            ccStockinfoInfo.setYjflag(null);
        }
        List<CcStockinfoInfo> list = ccStockinfoInfoService.selectCcStockinfoInfoListMobile(ccStockinfoInfo);
        return getDataTable(list);
    }


    /**
     * 预警库存
     */
    @ApiOperation("库存预警列表")
   // @PreAuthorize("@ss.hasPermi('business:stockinfo:listYj')")
    @GetMapping("/listYj")
    public TableDataInfo listYj(CcStockinfoInfo ccStockinfoInfo)
    {
        startPage();
        ccStockinfoInfo.setDeptId(SecurityUtils.getDeptId());
        List<CcStockinfoInfo> list = ccStockinfoInfoService.selectCcStockinfoInfoListYj(ccStockinfoInfo);
        return getDataTable(list);
    }





    /**
     * 导出库存信息列表
     */
    @PreAuthorize("@ss.hasPermi('business:stockinfo:export')")
    @Log(title = "库存信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CcStockinfoInfo ccStockinfoInfo)
    {
        ccStockinfoInfo.setDeptId(SecurityUtils.getDeptId());
        if("库存不足".equals(ccStockinfoInfo.getYjflag())){
            ccStockinfoInfo.setYjflag1("库存不足");
            ccStockinfoInfo.setYjflag(null);
        }
        List<CcStockinfoInfo> list = ccStockinfoInfoService.selectCcStockinfoInfoListJc(ccStockinfoInfo);
        ExcelUtil<CcStockinfoInfo> util = new ExcelUtil<CcStockinfoInfo>(CcStockinfoInfo.class);
        util.exportExcel(response, list, "库存信息数据");
    }

    /**
     * 获取库存信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:stockinfo:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(ccStockinfoInfoService.selectCcStockinfoInfoById(id));
    }

    /**
     * 新增库存信息
     */
    @PreAuthorize("@ss.hasPermi('business:stockinfo:add')")
    @Log(title = "库存信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CcStockinfoInfo ccStockinfoInfo)
    {
        ccStockinfoInfo.setDeptId(SecurityUtils.getDeptId());
        return toAjax(ccStockinfoInfoService.insertCcStockinfoInfo(ccStockinfoInfo));
    }

    /**
     * 修改库存信息
     */
    @PreAuthorize("@ss.hasPermi('business:stockinfo:edit')")
    @Log(title = "库存信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CcStockinfoInfo ccStockinfoInfo)
    {
        return toAjax(ccStockinfoInfoService.updateCcStockinfoInfo(ccStockinfoInfo));
    }
    @Log(title = "库存调整库位信息", businessType = BusinessType.UPDATE)
    @GetMapping(value = "editStockinfoKuWei/{ids}/{kuweiCode}")
    public AjaxResult editStockinfoKuWei(@PathVariable("ids") Long[] ids,@PathVariable("kuweiCode") String kuweiCode )
    {
        return toAjax(ccStockinfoInfoService.updateStockinfoKuWei(ids,kuweiCode));
    }

    /**
     * 删除库存信息
     */
    @PreAuthorize("@ss.hasPermi('business:stockinfo:remove')")
    @Log(title = "库存信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(ccStockinfoInfoService.deleteCcStockinfoInfoByIds(ids));
    }
}
